import numpy as np
import csv
from collections import Counter
# 空向量的创建
vector = np.empty(10)
print("空向量:", vector, "\n")

# 找0
array = [1,2,0,0,4,0]
print("索引为:",end="")
s = ""
for i in range(0, len(array)):
    if array[i] == 0:
        s += str(i) + ","
print(s[:-1])

# 反转3至8之间的所有


array = input("输入一维数组,用逗号分割:")
array =[int(item) for item in array.split(",")]
try:
    for i in range(3, 6):
        temp = array[i]
        array[i] = array[10 - i]
        array[10 - i] = temp
except Exception as e:
    print(e.__str__())
print("反转后结果为:",array)




# 读取CSV文件
with open("data/job_info.csv", "r", encoding="gbk", newline="") as file:
    reader = csv.reader(file)
    # 读取所有数据
    data = list(reader)
    file.close()
# 增加列名
header = ["公司", "岗位", "工作地点", "工资", "发布时间"]
# 统计各个岗位的招聘需求数量

job_counts = Counter([row[1] for row in data])

# 找出招聘需求最多的岗位
most_common_job = job_counts.most_common(1)[0]

# 筛选出工作地点在深圳、广州、北京、上海的数据分析师招聘信息
beijing = [row for row in data if row[2][:2] == "北京" and row[1] == "数据分析师"]
shanghai = [row for row in data if row[2][:2] == "上海" and row[1] == "数据分析师"]
shenzhen = [row for row in data if row[2][:2] == "深圳" and row[1] == "数据分析师"]
guangzhou = [row for row in data if row[2][:2] == "广州" and row[1] == "数据分析师"]
# 记录指定地点工作的信息
with open("data/new_job_info.csv", "w", encoding="utf-8", newline="") as file:
    writer = csv.writer(file)
    new_data = beijing+shenzhen+shanghai+guangzhou
    new_data.insert(0,header)
    writer.writerows(new_data)
    file.close()

with open("data/job_info.csv", "w", newline="") as file:
    w = csv.writer(file)
    # 读取所有数据
    data.insert(0,header)
    w.writerows(data)

# 结果
print("招聘最多地点岗位为:", most_common_job[0])
print("工作地点在深圳、广州、北京、上海的数据分析师招聘信息,已成功记入new_job_info.csv")